<?php
/**
* 功能: 注册成功
* 创建日期:Thu Nov 24 09:35:18 CST 2011
* 最后更新:
* 作者: slash
*/

include_once("ThePage.class.php");
$page = new ThePage();

$temp_id = $page->userRequest->get("temp_id");
if(empty($temp_id))
{
	user_log(0,"-3013","error",$_SERVER['SCRIPT_NAME']);
	$temp = $page->userRequest->user_get_cookie('err_url');
	$err_url = empty($temp) ? "404" :urldecode($temp);
	jumpPage($err_url,'',3);
	exit();
}

//取得相关信息
$user_arr = @unserialize($page->mc->get(SFT.$temp_id));

if(empty($user_arr))
{
	//mc存储失效
	user_log(0,"-3009","error",$_SERVER['SCRIPT_NAME']);
	goToIndex(-3009);
	exit();
}

$icpcode = $user_arr['icpcode'];
$user_id = $user_arr['user_id'];
$user_name = $user_arr['user_name'];
$real_name = $user_arr['real_name'];
$identity_card = $user_arr['identity_card'];
$user_mob = $user_arr['user_mob'];
//验证手机验证码

$ver_code = isset($_POST['ver_code']) ? trim($_POST['ver_code']) : '';
$send_pj = Factory::getItemClass('id5_note');
if(!$send_pj->check_code($ver_code,$user_mob) || empty($ver_code)){
	user_log(0,"-3023","error",$_SERVER['SCRIPT_NAME']);
	header("HTTP/1.0 404 Not Found");
	exit();
}

//开始身份通认证
$reg = Factory::getItemClass('soapId5');
$result = $reg->regid5($real_name,$identity_card,$user_mob);
if(empty($result)){
	user_log(0,"-3025","error",$_SERVER['SCRIPT_NAME']);
	goToIndex('-3025');
	exit;
}
$rtncode = $result['response'][0]['code'];
$icp_arr = get_icpcode_info($icpcode);

//拼接回调url
$url = get_call_back_url($icpcode,$user_id,$result['response'][0]['idtagNo'],$rtncode);
$url = $user_arr['call_back_url']."?".$url;

$page->smarty->assign('user_name',$user_name);
$page->smarty->assign('coop_name',$icp_arr['name']);
$page->smarty->assign('url',$url);
$page->smarty->assign('coop_name',$icp_arr['name']);

$user_arr = @unserialize($page->mc->get(SFT.$temp_id));
if(empty($user_arr))
{
	//mc存储失效
	user_log(0,"-3009","error",$_SERVER['SCRIPT_NAME']);
	goToIndex(-3009);
	exit();
}

if($rtncode==10 || $rtncode==11){
	$page->smarty->assign('sttagid',$result['response'][0]['idtagNo']);
	//成功则修改MEM中得信息
	$sft = $result['response'][0]['idtagNo'];
	$user_arr['sft'] = intval($sft);
	$user_arr['state'] = 1;
		//将返回信息写入MEMCACHE
	$user_arr['gender'] = trim($result['response'][0]['gender']);
	$user_arr['phoneArea'] = trim($result['response'][0]['phoneArea']);
	$user_arr['mobile'] = trim($result['response'][0]['mobile']);
	$user_arr['astro'] = trim($result['response'][0]['astro']);
	$user_arr['addr'] = trim($result['response'][0]['addr']);
	$user_arr['age'] = trim($result['response'][0]['age']);
	$user_arr['photo'] = trim($result['response'][0]['photo']);
	$user_arr['name'] = trim($result['response'][0]['name']);
	$user_arr['birthday'] = trim($result['response'][0]['birthday']);
	$user_arr['result'] = 1;
	$user_arr['stid'] = intval($result['response'][0]['idtagNo']);
	//服务器端将数据POST给客户
	//$sync = Factory::getItemClass('send_info');
	$user_arr['key_code'] = set_app_key($icp_arr['key'],$user_id,intval($result['response'][0]['idtagNo']),$icpcode);
	//$rs = $sync->put_info($user_arr,$icp_arr['sync_url']);
	//unset($user_arr['key_code']);
	//print_r($rs);
	/*if($rs){
		$user_arr['send_state'] = 1;
	}else{
		user_log(0,"-3028","error",$_SERVER['SCRIPT_NAME']);
		$user_arr['send_state'] = 0;
	}*/
	//成功结果写入日志文档
	user_log($temp_id,"suc 3","suc",$_SERVER['SCRIPT_NAME']);
	$page->mc->set(SFT.$temp_id,serialize($user_arr));
	$page->userRequest->free("temp_id");
	
	$page->userRequest->user_set_cookie('err_url','',-3600);

	
	//将身份信息返回给对方
	$page->smarty->assign('gender',urlencode($result['response'][0]['gender']));
	//$page->smarty->assign('phoneArea',$result['response'][0]['phoneArea']);
	$page->smarty->assign('mobile',$result['response'][0]['mobile']);
	//$page->smarty->assign('astro',$result['response'][0]['astro);
	$page->smarty->assign('addr',urlencode($result['response'][0]['addr']));
	//$page->smarty->assign('age',$result['response'][0]['age']);
	//$page->smarty->assign('idcode',$result['response'][0]['idcode);
	$page->smarty->assign('photo',$result['response'][0]['photo']);
	$page->smarty->assign('name',urlencode($result['response'][0]['name']));
	//解密
	$id5_crypt = Factory::getItemClass("id5_crypt");
	$page->smarty->assign('password',$id5_crypt->DecryptString($result['response'][0]['password']));
	$page->smarty->assign('birthday',$result['response'][0]['birthday']);
	$page->smarty->assign('back_url',$icp_arr['call_back_url']);
	$page->smarty->assign('user_id',$user_id);
	$page->smarty->assign('result',1);
	$page->smarty->assign('key_code',$user_arr['key_code']);
	$page->smarty->assign('stid',intval($result['response'][0]['idtagNo']));
	$page->smarty->display('success1.tpl');
}
$page->smarty->assign('back_url',$icp_arr['call_back_url']);
if($rtncode=='02'){
	//注册失败，手机号码被注册过身份通用户
	user_log(0,"-3019","error",$_SERVER['SCRIPT_NAME']);
	$page->smarty->display('error.tpl');
	exit;
}
if($rtncode=='01'){
	//注册失败，身份信息被注册过身份通用户
	user_log(0,"-3020","error",$_SERVER['SCRIPT_NAME']);
	$page->smarty->display('error.tpl');
	exit;
}
if($rtncode=='-1'){
	//注册失败，身份信息被注册过身份通用户
	user_log(0,"-3027","error",$_SERVER['SCRIPT_NAME']);
	$page->smarty->display('error.tpl');
	exit;
}
